/*
 * Copyright (c) 2011 Shanda Corporation. All rights reserved.
 *
 * Created on 2011-11-28.
 */

package com.whq.knowverywell.util.httpclient;

import android.content.Context;

import com.whq.knowverywell.util.LogUtil;
import com.whq.knowverywell.util.NetworkUtil;
import com.whq.knowverywell.util.StringUtil;
import com.whq.knowverywell.util.constant.ErrorCodeConstant;

/**
 * 跟HttpClient相关的工具类.
 *
 * @author wanghuaiqiang
 */
public class HttpClientUtil {
    private static final String TAG = "HttpClientUtil";

    public static HttpResult callServer(Context ctx, String host, boolean isHttps, String path, String req, String encoding) {
    	
        if (StringUtil.isBlank(NetworkUtil.getNetworkType(ctx))){
        	if (NetworkUtil.isAirplaneModeOn(ctx)) {
        		return new HttpResult(ErrorCodeConstant.ERR_CODE_HTTP_AIRPLANE_MODE);
        	}
            return new HttpResult(ErrorCodeConstant.ERR_CODE_NO_NET);
        }
        
        HttpResult httpResult = HttpClientTools.httpGet(ctx, host, path, req, encoding);
        if (httpResult == null) {
            return new HttpResult(ErrorCodeConstant.ERR_CODE_HTTP_EXCEPTION, "resp null");
        }
        LogUtil.i(TAG, "[" + host + path + "?" + req + "] return[" + httpResult + "]");
        return httpResult;
    }
}
